//
//  SecondViewController.swift
//  学唐诗
//
//  Created by 申克 on 16/5/10.
//  Copyright © 2016年 shang_hongzhi. All rights reserved.
//

import UIKit

class SecondViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    var name : String!
    var poetrys :NSDictionary!
    
    var titlesArray : NSArray!
    var poetry : NSArray!
    var labelText :String!
    
    @IBOutlet weak var nameLabel: UILabel!
    
  
    
    @IBOutlet weak var myTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        myTableView.delegate = self
        myTableView.dataSource = self
        myTableView.backgroundColor = UIColor.clearColor()
        titlesArray = poetrys.allKeys
        let str = "作者："
        nameLabel.text = str + name
        let button = UIButton.init(type: UIButtonType.Custom)
        button.frame = CGRectMake(10, 0, 60, 40)
        button.setTitle("返回", forState: UIControlState.Normal)
        button.backgroundColor = UIColor.clearColor()
        button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        self.view.addSubview(button)
        button.addTarget(self, action: #selector(SecondViewController.returnButtonClick), forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    func returnButtonClick(){
        self.navigationController?.popViewControllerAnimated(true)
      
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titlesArray.count
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell.init(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
        cell.textLabel?.text = titlesArray[indexPath.row] as? String
        cell.backgroundColor = UIColor.clearColor()
        cell.selectionStyle = UITableViewCellSelectionStyle.None
        return cell
    }
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let third = ThirdViewController()
        third.poetryName = name
        third.poetryTitle = titlesArray[indexPath.row]as! String
        third.poetryStr = poetrys.objectForKey(third.poetryTitle)as! String
        self.navigationController?.pushViewController(third, animated: true)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
